<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>{$Think.lang.datagl}</title>
    <link rel="stylesheet" href="__ADMIN__/vendor/layui/css/layui.css">
    <link rel="stylesheet" href="__ADMIN__/custom/css/style.css">
</head>

<body style="padding:10px 10px;">
    <form action="" class="layui-form">
        <a style="float:left;margin-right: 10px;" href="javascript:;" class="layui-btn database layui-btn-danger">{$Think.lang.kuback}</a>
        <!-- <a style="float:left;margin-right: 10px;" href="javascript:;" class="layui-btn hyuan layui-btn-normal">还原数据</a> -->
        <a style="float:left;margin-right: 10px;" href="javascript:;" class="layui-btn layui-btn-warm " id="repair">{$Think.lang.plrepair}</a>
        <table class="layui-table" lay-size="sm">
            <colgroup>
                <col width="80">
                <col>
                <col width="80">
                <col width="150">
                <col width="100">
                <col width="100">
                <col width="100">
                <col width="200">
            </colgroup>
            <thead>
                <tr>
                    <th style="text-align: center;"><input type="checkbox" name="" lay-skin="primary"
                            lay-filter="quanxuan"></th>
                    <th>{$Think.lang.table}</th>
                    <th>{$Think.lang.num}</th>
                    <th>{$Think.lang.yqin}</th>
                    <th>{$Think.lang.dsize}</th>
                    <th>{$Think.lang.zfji}</th>
                    <th>{$Think.lang.shuom}</th>
                    <th>{$Think.lang.caoz}</th>
                </tr>
            </thead>
            <tbody>
                {volist name="list" id="vo"}
                <tr>
                    <td style="text-align: center;">
                        <input type="checkbox" name="tables[]" class="qx" lay-skin="primary" value="{$vo.name}">
                    </td>
                    <td>{$vo.name}</td>
                    <td>{$vo.rows}</td>
                    <td>{$vo.engine}</td>
                    <td>{:size_format($vo.data_length+$vo.index_length,2)}</td>
                    <td>{$vo.collation}</td>
                    <td>{$vo.comment}</td>
                    <td>
                        <a href="javascript:;" onclick="repair('{$vo.name}')" class="layui-btn layui-btn-mini">{$Think.lang.repair}</a>
                        <a href="javascript:;" onclick="optimize('{$vo.name}')"
                            class="layui-btn layui-btn-warm layui-btn-mini">{$Think.lang.optimize}</a>
                            <!-- <a href="javascript:;" onclick="x_admin_show('{$vo.name}-备份','{:url("admin/database/importlist",["name"=>$vo.name])}',800,400)" class="layui-btn beifen layui-btn-danger layui-btn-mini dels">备份</a> -->
                        <a href="javascript:;" data="{$vo.name}" class="layui-btn beifen layui-btn-danger layui-btn-mini del">{$Think.lang.backup}</a></td>
                </tr>
                {/volist}
            </tbody>
        </table>
    </form>
    <script src="__ADMIN__/vendor/js/jquery.js"></script>
    <script src="__ADMIN__/vendor/layui/layui.js"></script>
    <script src="__ADMIN__/custom/js/admin.js"></script>
    <script>
        layui.use(['layer', 'form'], function () {
            var layer = layui.layer;
            var form = layui.form;
            // 全选与取消
            form.on('checkbox(quanxuan)', function (data) {
                if (data.elem.checked) {
                    $('.qx').prop("checked", "checked");
                    form.render();
                } else {
                    $('.qx').prop("checked", "");
                    form.render();
                }

            });
            

        });
        // 还原全部
        $(".hyuan").click(function(){
            $.post("{:url('admin/Database/restore')}",{tables:tables},function(res){
                if (res.code == 1) {
                        layer.msg(res.msg, { time: 1000, icon: 1 });
                    } else {
                        layer.msg(res.msg, { time: 1000, icon: 2 });
                    }
            })
        });
        // 数据库备份事件
        $(".database").click(function () {
                var name ="database";
                layer.open({
                    type: 2,
                    title: name+'备份',
                    area: ['800px', '500px'],
                    fixed: false, //不固定
                    maxmin: true,
                    content: '{:url("database/backuplist")}?name=' + name //数组第二项即吸附元素选择器或者DOM
                });
            });
          // 备份点击事件
          $(".beifen").click(function () {
                var name = $(this).attr("data");
                layer.open({
                    type: 2,
                    title: name+'备份',
                    area: ['800px', '500px'],
                    fixed: false, //不固定
                    maxmin: true,
                    content: '{:url("database/backuplist")}?name=' + name //数组第二项即吸附元素选择器或者DOM
                });
            });
        // 批量修复
        var tables = "";
        $("#repair").click(function () {
            $("input[type='checkbox']:checkbox:checked").each(function () {
                if($(this).val()=="on"){
                    tables += "";
                }else{
                    tables += $(this).val()+",";
                }
                
            });
            $.post("{:url('admin/Database/repairAll')}",{tables:tables},function(res){
                if (res.code == 1) {
                        layer.msg(res.msg, { time: 1000, icon: 1 });
                    } else {
                        layer.msg(res.msg, { time: 1000, icon: 2 });
                    }
            })
        });
            //修复
            function repair(tablename) {
                $.post("{:url('admin/Database/repair')}", { tablename: tablename }, function (res) {
                    if (res.code == 1) {
                        layer.msg(res.msg, { time: 1000, icon: 1 });
                    } else {
                        layer.msg(res.msg, { time: 1000, icon: 2 });
                    }

                }, 'json');
            }
            //优化
            function optimize(tablename) {
                $.post("{:url('admin/Database/optimize')}", { tablename: tablename }, function (res) {
                    if (res.code == 1) {
                        layer.msg(res.msg, { time: 1000, icon: 1 });
                    } else {
                        layer.msg(res.msg, { time: 1000, icon: 2 });
                    }
                }, 'json');
            }
            $(function () {
                $(window.parent.document).find('#righttitle').text($('title').text());
            });
    </script>
</body>

</html>